/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fiad.gui.components;

import javax.swing.SpinnerNumberModel;

/**
 *
 * @author MJ
 */
public class NotenSpinnerModel extends SpinnerNumberModel {

    private double currentValue = 1.0;
    private boolean teilnote;

    public NotenSpinnerModel(boolean teilnote) {
        super();
        this.teilnote = teilnote;
    }

    @Override
    public Object getValue() {
        return currentValue;
    }

    @Override
    public Object getNextValue() {
        if (currentValue < 6.0) {
            currentValue += 0.01;
        }
        return currentValue;
    }

    @Override
    public Object getPreviousValue() {
        if (currentValue > 1.0 || currentValue > 0.75 && teilnote) {
            currentValue -= 0.01;
        }
        return currentValue;

    }

    @Override
    public void setValue(Object value) {
        currentValue = (Double) value;
        if (currentValue > 6) {
            currentValue = 6;
        } else if (currentValue < 1.0 && !teilnote) {
            currentValue = 1.0;
        } else if (currentValue < 0.75 && teilnote) {
            currentValue = 0.75;
        }
        fireStateChanged();
    }
}
